package discrete.math;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class InputPanel extends JPanel implements ActionListener {
	
	private MatrixMath matrix = new MatrixMath();
	private JButton createMatrix;
	private JTextArea mrowsX;
	
	public InputPanel(MatrixMath matrix, String str) {
		this.matrix = matrix;
		
		this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		JLabel header = new JLabel(str);
		mrowsX = new JTextArea(1,1);
		if(matrix.getMrows() > 1) {
			mrowsX.setText(String.valueOf(matrix.getMrows() - 1));
		} else {
			mrowsX.setText(String.valueOf(matrix.getMrows()));
		}
		
		header.setHorizontalAlignment(JLabel.CENTER);
		createMatrix = new JButton("CreateMatrix");		
		
		c.fill = GridBagConstraints.CENTER;
		c.weightx = 0.05;
		c.gridx = 1;
		c.gridy = 0;
		this.add(header, c);
		
		c.fill = GridBagConstraints.EAST;
		c.weightx = 0.1;
		c.gridx = 1;
		c.gridy = 1;
		this.add(mrowsX, c);
		
		
		c.fill = GridBagConstraints.CENTER;
		c.weightx = 0.05;
		c.gridx = 1;
		c.gridy = 2;
		this.add(createMatrix, c);
		
		createMatrix.addActionListener(this);
	}

	public InputPanel(boolean doubleBuffered, MatrixMath matrix, String str) {
		this(matrix, str);
		this.setDoubleBuffered(doubleBuffered);
	}

	public void actionPerformed(ActionEvent e) {
		int mrows = Integer.parseInt(mrowsX.getText()) + 1;			
		matrix = new MatrixMath(mrows);
		new GraphTheoryGUI();
	}

	public MatrixMath getMatrix() {
		return matrix;
	}

	public void setMatrix(MatrixMath matrix) {
		this.matrix = matrix;
	}
}